
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Order_Item.h"
using namespace std;

Order_Item::Order_Item (int seatid, int orderid, int menu_itemid, int qty)
{
	Order_Item::seat_id = seatid;
	Order_Item::order_id = orderid;
	Order_Item::menu_item_id = menu_itemid;
	Order_Item::prod_qty = qty;
}

void Order_Item::display()
{
	cout << "\nSeat ID:\t" << seat_id;
	cout << "\nOrder ID:\t" << order_id;
	cout << "\nMenu Item ID:\t"<<menu_item_id;
	cout << "\nQuantity Ordered:\t" << prod_qty << endl;
}
	
void read_items(vector<Order_Item>& item_list, string filepath)
{
	ifstream inFile;
	inFile.open((char*)filepath.c_str());
	if(inFile.fail())
	{
		cerr << "\n\nERROR: Unable to open file orders.dat\n\n";
	}
	
	int end;
	inFile >> end;
	
	//this skips the first half of the .dat file
	for(int i = 0;i < end*8;i++)
	{
		int temp;
		inFile >> temp;
	}
	
	//having skipped to part 2 of the file, we can begin reading and storing the information
	inFile >> end;
	for(int i = 0; i<end; i++)
	{
		int seatid, orderid, menu_itemid, qty;
		char check;
		inFile >> check;
		switch(check)
		{
			case 'A':
				seatid = 1;
				break;
			case 'B':
				seatid = 2;
				break;
			case 'C':
				seatid = 3;
				break;
			case 'D':
				seatid = 4;
				break;
			case 'E':
				seatid = 5;
				break;
			case 'F':
				seatid = 6;
				break;
			case 'G':
				seatid = 7;
				break;
			case 'H':
				seatid = 8;
				break;
			default:
				seatid = 0;
		}
		
		inFile >> orderid >> menu_itemid >> qty;
		
		item_list.push_back(Order_Item(seatid, orderid, menu_itemid, qty));
	}
}
